Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

351
Views
Use bluebird para mangosta, obtuve ".bind no es una función"

Uso bluebird para mangosta :

 const Promise = require("bluebird"); const mongoose = require("mongoose"); mongoose.Promise = Promise;

Y quiero usar Promise.bind para compartir variables en la cadena de promesas:

 function getAutherOfBook(name) { return Book.findOne( { name: name }, "-_id auther") .then(doc => { return doc.auther; }); }; function geNationalityOfAuther(name) { return Auther.findOne( { name: name }, "-_id nationality") .then(doc => { return doc.nationality; }); }; getAutherOfBook("The Kite Runner") .bind({}) .then(auther => { this.auther = auther; return geNationalityOfAuther(auther); }) .then(nationality => { console.log("auther: ", this.auther); console.log("nationality: ", nationality); }) .bind()

Pero recibí el error: getAutherOfBook(...).bind no es una función

¿Quizás bluebird no está funcionando para mangosta?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

El problema que tiene es que las consultas de mongoose no devuelven promesas completas, citando directamente http://mongoosejs.com/docs/promises.html (v4.7.6)

 // A query is not a fully-fledged promise, but it does have a `.then()`. query.then(function (doc) { // use doc }); // `.exec()` gives you a fully-fledged promise var promise = query.exec(); assert.ok(promise instanceof require('mpromise'));

En otras palabras, la función then es azúcar de sintaxis y no una promise , por lo que la bind y otras funciones de promesa no funcionan.

Para que funcione, lo envuelve en una promesa completa o usa la función exec como se sugiere en los documentos

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!